package adavance.socket;

import java.io.*;
import java.net.Socket;
import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class ObjectThread extends Thread {
    private Socket s;
    private static Map<String,String> map=new HashMap<>();
    static{
        //静态块/匿名静态方法
        map.put("dog","狗");
        map.put("clsName","java81");
        map.put("zuishuai","马晓波");
        map.put("zuipang","马晓波");
        map.put("腿最长","马晓波");
    }
    public ObjectThread(Socket s){
        this.s=s;
    }

    @Override
    public void run() {
        try{
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            //构建oin和oout的顺序要和我相反
            ObjectInputStream oin=new ObjectInputStream(in);
            ObjectOutputStream oout=new ObjectOutputStream(out);
            oout.writeObject(map);//能序列化的对象
            oout.flush();
            Object obj = oin.readObject();
            System.out.println("从"+s+"这里收到了："+obj);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                s.close();
            } catch (Exception e) {

            }
        }

    }
}
